from devtools import debug
from pydantic import Field, ValidationError

from my_typing import *
from utils.validator_utils.pydantic_validator.base import BaseModelV1
from utils.validator_utils.pydantic_validator.parser import parse_model_fields

import utils.enum_utils as enum

class Hobby(BaseModelV1):
    name: str = Field(..., title="名称", min_length=1, max_length=10)
    years: int = Field(..., title="持续时长", ge=1, le=100)


class User(BaseModelV1):
    name: str = Field(..., title="姓名", min_length=3, max_length=20)
    # hobbies: list[Hobby] = Field(..., title="爱好")
    gender: int = Field(1, title="性别", const=True)
    is_true: bool
    # fl: Decimal = Field(..., title="小数", max_digits=2, decimal_places=2)



try:
    u1 = User(
        name=123,
        # hobbies=[
        #     {
        #         "years": "asd",
        #         "age": 3
        #     }
        # ],
        # fl=20.22311,
        gender=2,
        is_true=1234
    )
except ValidationError as e:
    model = e.model
    dic = {}
    parse_model_fields(model, dic)
    debug(dic)
    debug(e.errors())
